package com.sjlh.centurylianhua.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sjlh.centurylianhua.dto.SearchCon;
import com.sjlh.centurylianhua.entity.Sale;
import com.sjlh.centurylianhua.mapper.SaleMapper;
import com.sjlh.centurylianhua.utils.Result;
import com.sjlh.centurylianhua.utils.ResultData;
import com.sjlh.centurylianhua.utils.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;


@CrossOrigin
@RestController
@RequestMapping("/sale")
public class SaleController {
    @Resource
    private SaleMapper saleMapper;

    @RequestMapping("/add")
    public Object add(@RequestBody Sale sale){
        System.out.println(sale);
        sale.setRemarks1("SJLH"+new Date().getTime());
        System.out.println(sale);
        long r=saleMapper.insert(sale);
        long saleId=sale.getSaleId();
        if (r==1)
            return new ResultData(true,20000,"添加成功！",true,saleId);
        else
            return new ResultData(true,20000,"添加失败！",false,null);
    }
    @RequestMapping("/del")
    public Object del(@RequestBody Sale sale){
        System.out.println(sale);
        int r=saleMapper.deleteById(sale.getSaleId());
        if(r==1)
            return new ResultData(true,20000,"删除成功！",true,null);
        else
            return new ResultData(true,20000,"删除失败！",false,null);


    }
}
